#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@File    :   main.py    
@Contact :   291622538@qq.com

@Modify Time      @Author    @Version    @Description
------------      -------    --------    -----------
2021/3/31 14:29   fan        1.0         None
"""
import csv
import time

from tools.port_scan.tcp_scan_socket import tcp_scan

if __name__ == '__main__':
    s_time = time.time()

    ip = "157.7.33.53"

    is_open_result = []

    with open('data/IP.csv', 'r', encoding='UTF-8-sig') as f:

        for num, line in enumerate(csv.reader(f)):

            if num == 0:
                is_open_result.append([line[0], line[1], line[2], "是否是域名服务器"])
                continue

            # if num == 10:
            #     break

            # print(line)
            ip = line[0]
            location = line[1]
            in_or_out = line[2]
            result = tcp_scan(ip, 53)
            # print(result)

            is_open_result.append([ip, location, in_or_out, result])
    # print(is_open_result)

    with open('data/IP-result.csv', 'w', encoding='utf-8', newline='') as f:
        writer = csv.writer(f)

        writer.writerows(is_open_result)

    e_time = time.time()

    print("scan time is ", e_time - s_time)
    print("结束的时间：", e_time)
